package com.yu.gulimall.search.controller;

import com.yu.common.es.SkuEsModel;
import com.yu.common.exception.BizExceptionCode;
import com.yu.common.utils.R;
import com.yu.gulimall.search.service.ProductSaveService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@RequestMapping("/search/save")
@RestController
public class EsProductSaveController {


    @Resource
    private ProductSaveService productSaveService;
    @PostMapping
    public R productEsUp(@RequestBody List<SkuEsModel> skuEsModels){
        try {
            productSaveService.productEsUp(skuEsModels);
        } catch (IOException e) {
            return R.error(BizExceptionCode.PRODUCT_UP_EXCEPTION.getCode(), BizExceptionCode.PRODUCT_UP_EXCEPTION.getMsg());
        }
        return R.ok();
    }
}
